package com.senven.api.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.senven.api.annotation.LogInfo;
import com.senven.api.commom.ResponsePage;
import com.senven.api.dao.OrganActivityMapper;
import com.senven.api.pojo.OrganActivity;
import com.senven.api.pojo.OrganAffair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrganActivityService {
    @Autowired
    private OrganActivityMapper organActivityMapper;


    /**
     * 获取进行中社团活动
     * @param current
     * @param size
     * @return
     */

    public ResponsePage<OrganActivity> queryOrganActivityListActive(int current, int size){
        Page<OrganActivity> page = new Page<OrganActivity>(current, size);
        QueryWrapper<OrganActivity> wrapper = new QueryWrapper<OrganActivity>();
        wrapper.eq("status",1);

        IPage<OrganActivity> iPage = organActivityMapper.selectPage(page,wrapper);
        ResponsePage<OrganActivity> responsePage= new ResponsePage<OrganActivity>();
        responsePage.makePage(iPage);
        return responsePage;
    }

    /**
     * 获取社团活动
     * @param oid
     * @param current
     * @param size
     * @return
     */

    public ResponsePage<OrganActivity> queryOrganActivityListById(int oid, int current, int size){
        Page<OrganActivity> page = new Page<OrganActivity>(current, size);
        QueryWrapper<OrganActivity> wrapper = new QueryWrapper<OrganActivity>();
        wrapper.eq("oid",oid);

        IPage<OrganActivity> iPage = organActivityMapper.selectPage(page,wrapper);

        ResponsePage<OrganActivity> responsePage= new ResponsePage<OrganActivity>();
        responsePage.makePage(iPage);

        return responsePage;
    }


    /**
     * 所有人都可看见社团活动
     * @param current
     * @param size
     * @return
     */
    public ResponsePage<OrganActivity> queryOrganActivityList(int current, int size){
        Page<OrganActivity> page = new Page<OrganActivity>(current, size);

        IPage<OrganActivity> iPage = organActivityMapper.selectPage(page,null);

        ResponsePage<OrganActivity> responsePage= new ResponsePage<OrganActivity>();
        responsePage.makePage(iPage);

        return responsePage;
    }

    /**
     * 名称查询社团活动
     * @param name
     * @param current
     * @param size
     * @return
     */
    public ResponsePage<OrganActivity> queryOrganActivityListByName(String name, int current, int size){
        Page<OrganActivity> page = new Page<OrganActivity>(current, size);
        QueryWrapper<OrganActivity> wrapper = new QueryWrapper<OrganActivity>();
        wrapper.like("name",name);

        IPage<OrganActivity> iPage = organActivityMapper.selectPage(page,wrapper);
        ResponsePage<OrganActivity> responsePage= new ResponsePage<OrganActivity>();
        responsePage.makePage(iPage);

        return responsePage;
    }

    /**
     * 插入一条社团活动
     * @param 
     * @return
     */
    @LogInfo(operateInfo = "插入社团")
    public int insertOrganActivity(OrganActivity organActivity){

        int result = organActivityMapper.insert(organActivity);
        return result;
    }

    /**
     * 删除一条社团活动
     * @param id
     * @return
     */
    @LogInfo(operateInfo = "删除社团")
    public int deleteOrganActivity(int id){
        int result = organActivityMapper.deleteById(id);
        return result;
    }

    /**
     * 更新一条
     * @return
     */
    @LogInfo(operateInfo = "更新社团")
    public int updateOrganActivity(OrganActivity organActivity) {
        int result = organActivityMapper.updateById(organActivity);
        return result;
    }

}
